package student.dao;
import java.sql.Statement;
import util.MysqlUtil;
import java.sql.ResultSet;
import student.entity.Student;
import java.sql.SQLException;


public class StudentDao {
    public void studentSelect() {
        try {
            Statement jbdc = MysqlUtil.JBDC();
            String sql = "select * from student";
            ResultSet resultSet = jbdc.executeQuery(sql);
            while(resultSet.next()){
                int studentId = resultSet.getInt("student_id");
                String studentName = resultSet.getString("student_name");
                String studentLoginName = resultSet.getString("student_login_name");
                String studentLoginPassword=resultSet.getString("student_login_password");
                int studentAge = resultSet.getInt("student_age");
                String studentSex = resultSet.getString("student_sex");
                String classId=resultSet.getString("class_id");
                System.out.println("  ");
                System.out.print("id："+studentId);
                System.out.print(" 名字："+studentName);
                System.out.print(" 账号："+studentLoginName);
                System.out.print(" 密码："+studentLoginPassword);
                System.out.print(" 年龄："+studentAge);
                System.out.print(" 性别："+studentSex);
                System.out.println(" 班级："+classId);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
public void studentClass(){
    try {
        Statement jbdc = MysqlUtil.JBDC();
        String sql = "select * from student_class";
        ResultSet resultSet = jbdc.executeQuery(sql);
        while(resultSet.next()){
            String classYear = resultSet.getString("class_year");
            String classSemester = resultSet.getString("class_semester");
            int classId=resultSet.getInt("class_id");
            String className = resultSet.getString("class_name");
            String classTime=resultSet.getString("class_time");
            String classWeek=resultSet.getString("class_week");
            String classSite = resultSet.getString("class_site");
            System.out.println(" ");
            System.out.print("学年："+classYear);
            System.out.print(" 学期："+classSemester);
            System.out.print(" 课程编号："+classId);
            System.out.print(" 课程名称："+className);
            System.out.print(" 课程时间："+classTime);
            System.out.print(" 课程周数："+classWeek);
            System.out.println(" 课程地点："+classSite);
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    }
    public void studentGrade(){
        try {
            Statement jbdc = MysqlUtil.JBDC();
            String sql = "select * from student_grade";
            ResultSet resultSet = jbdc.executeQuery(sql);
            while(resultSet.next()){
                String classYear = resultSet.getString("class_year");
                String classSemeter = resultSet.getString("class_semeter");
                int classId=resultSet.getInt("class_id");
                String classLoginName = resultSet.getString("class_login_name");
                String classQulity=resultSet.getString("class_qulity");
                String classGrade=resultSet.getString("class_grade");
                System.out.println(" ");
                System.out.print("学年："+classYear);
                System.out.print(" 学期："+classSemeter);
                System.out.print(" 课程编号："+classId);
                System.out.print(" 课程名称："+classLoginName);
                System.out.print(" 课程性质："+classQulity);
                System.out.println(" 课程成绩："+classGrade);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public void studentRevise(Student student){
        try {
            Statement jbdc = MysqlUtil.JBDC();
            String sql = "update student set student_name="+"\""+student.getStudentName()+"\",student_age="
                    + "\""+student.getStudentAge()+"\",student_sex="
                    +"\""+student.getStudentSex()+"\",class_id="
                    +"\""+student.getStudentClass()+"\""+"where student_id ="+student.getStudentId();
            boolean execute = jbdc.execute(sql);
            System.out.println("修改成功");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
